//
//  CarSourcesRecommendDetailVC.m
//  NtoccShipper
//
//  Created by mac on 2019/12/27.
//  Copyright © 2019 zhuchongjin. All rights reserved.
//

#import "CarSourcesRecommendDetailVC.h"
#import "CarSourceInfoDetailCell.h"
#import "HCSStarRatingView.h"

@interface CarSourcesRecommendDetailVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) CarSourceInfoDetailCell *carSourceInfoDetailCell;
@property (nonatomic,strong) CJTableView *tableView;
@property (nonatomic,strong) NSMutableArray *modelArray;
@property (nonatomic,strong) NSMutableArray *arrContents;
@property (nonatomic,strong) HCSStarRatingView *viewRate;
@property (nonatomic,strong) CJView *viewStar;
@property (nonatomic,strong) CJLabel *labStarNum;
@end

@implementation CarSourcesRecommendDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setTitleName:@"车源信息"];
    [self setBackLeftButton:@""];
    self.carSourceInfoDetailCell = [[CarSourceInfoDetailCell alloc]initWithFlex:nil reuseIdentifier:nil];
    [self loadData];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
}

- (void)loadData{

    NSString *strNil = @"";
    self.arrContents = [[NSMutableArray alloc]initWithObjects:self.model.driverName,self.model.driverPhone,CJStringWithFormat(@"%@ %@ %@",[CJRegular getIsStrEmpty:self.model.licenseNumber] ? strNil: self.model.licenseNumber,[CJRegular getIsStrEmpty:self.model.vehicleTypeName] ? strNil:self.model.vehicleTypeName,[CJRegular getIsStrEmpty:self.model.loadStatusName] ? strNil:self.model.loadStatusName),IsNilOrNull(self.model.lastLocation) ? @"":self.model.lastLocation,self.model.content,self.model.destination,self.model.departure,self.model.gmtCreated, nil];
    
    [self.view addSubview:self.tableView];
    
    CGRect rcFrame = CGRectMake(0, kTopHeight, [[UIScreen mainScreen] bounds].size.width, 0);
    FlexFrameView *header = [[FlexFrameView alloc] initWithFlex:@"CarSourceRecommendDetailTopView" Frame:rcFrame Owner:self];
    header.flexibleHeight = YES;

    [self.viewStar addSubview:self.viewRate];
    self.viewRate.value =  self.model.grade/20;
    self.labStarNum.text = @(self.model.grade).cj_description;
    
    [header layoutIfNeeded];
    self.tableView.tableHeaderView = header;
    [self.tableView reloadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.modelArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identifier = @"CarSourceInfoDetailCell";
    CarSourceInfoDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[CarSourceInfoDetailCell alloc] initWithFlex:nil reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    [cell setCellInfoWithTitle:self.modelArray[indexPath.row] content:self.arrContents[indexPath.row]];
    return cell;
}

- (NSMutableArray *)modelArray{
    if (!_modelArray) {
        _modelArray = [[NSMutableArray alloc]initWithObjects:@"车主",@"联系电话",@"车辆信息",@"当前位置",@"备注信息",@"起始地",@"目的地",@"发布时间" ,nil];
    }
    return _modelArray;
}

- (HCSStarRatingView *)viewRate{
    if (!_viewRate) {
      _viewRate =   [[HCSStarRatingView alloc]initWithFrame:CGRectMake(0,0,130,35)];
        _viewRate.tintColor = [UIColor cjStarRateColor];
        _viewRate.starBorderColor = [UIColor cjClearColor];
        _viewRate.emptyStarColor = [UIColor cjEmptyStarRateColor];
        _viewRate.backgroundColor = [UIColor cjClearColor];
        _viewRate.enabled = NO;
        _viewRate.maximumValue = 5;
        _viewRate.allowsHalfStars = YES;
        _viewRate.minimumValue = 0;
    }
    return  _viewRate;
}

- (CJTableView *)tableView{
    if (!_tableView) {
        _tableView = CJTableView.tbInitFrameStyle(CGRectMake(0, kTopHeight + CJTableToTopHeight, SCREEN_WIDTH, SCREEN_HEIGHT-kTopHeight - CJTableToTopHeight),UITableViewStylePlain)
        .tbDelegate(self)
        .tbDataSource(self)
        .tbSetOther(YES)
        .tbEstimatedRowHeight(YES)
        ;
    }
    return _tableView;
}


@end
